package com.zxjbyte.yiyi.framework.oss.client;

import cn.hutool.extra.spring.SpringUtil;
import com.zxjbyte.yiyi.framework.oss.config.OssProperties;
import com.zxjbyte.yiyi.framework.oss.enums.OssStorageEnum;
import com.zxjbyte.yiyi.framework.oss.storage.FileMetadata;
import com.zxjbyte.yiyi.framework.oss.storage.OssOperations;
import com.zxjbyte.yiyi.framework.oss.storage.OssPutResult;
import com.zxjbyte.yiyi.framework.oss.storage.db.DbOssTemplate;
import com.zxjbyte.yiyi.framework.oss.storage.local.LocalOssTemplate;
import com.zxjbyte.yiyi.framework.oss.storage.s3.S3OssTemplate;

import java.io.InputStream;

/**
 * 主文件客户端类
 *
 * @Author zhangxingjia
 * @Date 2023/6/19 15:36
 * @Version: 1.0
 */
public class MasterFileClient implements FileClient {

    private final OssOperations operations;

    public MasterFileClient(OssProperties properties){
        if(OssStorageEnum.S3 == properties.getStorage()){
            operations = SpringUtil.getBean(S3OssTemplate.class);
        } else if (OssStorageEnum.DB == properties.getStorage()){
            operations = SpringUtil.getBean(DbOssTemplate.class);
        } else {
            operations = SpringUtil.getBean(LocalOssTemplate.class);
        }
    }

    @Override
    public FileMetadata statFile(String path) {
        return operations.statFile(path);
    }

    @Override
    public OssPutResult putFile(InputStream input, String path) {
        return operations.putFile(input, path);
    }

    @Override
    public boolean deleteFile(String path) {
        return operations.deleteFile(path);
    }
}
